import { useState } from 'react';

const usePagination = () => {
   const [pagination, setPagination] = useState({
      page: 1,
      pageSize: 10,
      total: 0,
   });
   const [pageRefresh, setPageRefresh] = useState(false);

   const config = {
      size: 'small',
      showQuickJumper: false,
      total: pagination.total,
      current: pagination.page,
      showSizeChanger: true,
      onChange: (current) => {
         setPagination({
            ...pagination,
            page: current,
         });
         setPageRefresh(() => !pageRefresh);
      },
      pageSize: pagination.pageSize,
      onShowSizeChange: (page, pageSize) => {
         setPagination({
            page,
            pageSize,
         });
         setPageRefresh(() => !pageRefresh);
      },
   };

   return {
      pagination,
      pageRefresh,
      setPagination,
      paginationConfig: config,
   };
};

export default usePagination;
